package com.baizhi.hospital.service.impl;

import com.baizhi.hospital.dao.HospLogDao;
import com.baizhi.hospital.entity.HospLog;
import com.baizhi.hospital.service.HospLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HospLogServiceImpl implements HospLogService {
	private Logger logger  = LoggerFactory.getLogger(HospLogServiceImpl.class);
	@Resource
	private HospLogDao hospLogDao;
	@Override
	public Map<String, Object> selectLog(int page, int limit, String name) {
		logger.info("查询所有的日志");
		if (name!=null && !"".equals(name)){
			name = "%"+name+"%";
		}else{
			name=null;
		}

		int offset = (page-1)*limit;
		List<HospLog> hospLogs = hospLogDao.selectLogPage(offset, limit, name);
		int count = hospLogDao.selectCount(name);
		HashMap<String, Object> map = new HashMap<>();
		map.put("data",hospLogs);
		map.put("count",count);
		map.put("code",0);
		map.put("msg","");
		return map;
	}


	@Override
	public int insertLog(HospLog hospLog) {
		return hospLogDao.insertLog(hospLog);
	}
}
